# Copyright (C) 2009 Lemur Consulting Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import collections

# data extracted from http://en.wikipedia.org/wiki/List_of_colors

rgb_data = {
    "Air Force blue"        :  (93 ,138,168),
    "Alice blue"            :  (240,248,255),
    "Alizarin"              :  (227,38 ,54 ),
    "Amaranth"              :  (229,43 ,80 ),
    "Amaranth Pink"         :  (241,156,187),
    "Amber"                 :  (255,191,0  ),
    "Amber (SAE/ECE),"       :  (255,126,0  ),
    "Amethyst"              :  (153,102,204),
    "Apricot"               :  (251,206,177),
    "Aqua"                  :  (0  ,255,255),
    "Aquamarine"            :  (127,255,212),
    "Army green"            :  (75 ,83 ,32 ),
    "Arsenic"               :  (59 ,68 ,75 ),
    "Asparagus"             :  (123,160,91 ),
    "Atomic tangerine"      :  (255,153,102),
    "Auburn"                :  (109,53 ,26 ),
    "Azure (color wheel),"   :  (0  ,127,255),
    "Azure (web color),"     :  (240,255,255),
    "Baby blue"             :  (224,255,255),
    "Beige"                 :  (245,245,220),
    "Bistre"                :  (61 ,43 ,31 ),
    "Black"                 :  (0  ,0  ,0  ),
    "Blue"                  :  (0  ,0  ,255),
    "Blue (pigment),"        :  (51 ,51 ,153),
    "Blue (RYB),"            :  (2  ,71 ,254),
    "Blue-green"            :  (0  ,221,221),
    "Indigo"                :  (138,43 ,226),
    "Bole"                  :  (121,68 ,59 ),
    "Bondi blue"            :  (0  ,149,182),
    "Brandeis Blue"         :  (0  ,112,255),
    "Brass"                 :  (181,166,66 ),
    "Bright green"          :  (102,255,0  ),
    "Bright pink"           :  (255,0  ,127),
    "Bright turquoise"      :  (8  ,232,222),
    "Brilliant rose"        :  (255,85 ,163),
    "Brink Pink"            :  (251,96 ,127),
    "British racing green"  :  (0  ,66 ,37 ),
    "Bronze"                :  (205,127,50 ),
    "Brown"                 :  (150,75 ,0  ),
    "Buff"                  :  (240,220,130),
    "Burgundy"              :  (128,0  ,32 ),
    "Burnt orange"          :  (204,85 ,0  ),
    "Burnt sienna"          :  (233,116,81 ),
    "Burnt umber"           :  (138,51 ,36 ),
    "Byzantium"             :  (112,41 ,99 ),
    "Camouflage green"      :  (120,134,107),
    "Caput Mortuum"         :  (89 ,39 ,32 ),
    "Cardinal"              :  (196,30 ,58 ),
    "Carmine"               :  (150,0  ,24 ),
    "Carmine Pink"          :  (235,76 ,66 ),
    "Carnation pink"        :  (255,166,201),
    "Carnelian"             :  (179,27 ,27 ),
    "Carolina blue"         :  (153,186,227),
    "Carrot orange"         :  (237,145,33 ),
    "Celadon"               :  (172,225,175),
    "Cerise"                :  (222,49 ,99 ),
    "Cerise Pink"           :  (236,59 ,131),
    "Cerulean"              :  (0  ,123,167),
    "Cerulean blue"         :  (42 ,82 ,190),
    "Champagne"             :  (247,231,206),
    "Charcoal"              :  (70 ,70 ,70 ),
    "Chartreuse (traditional),": (223,255,0  ),
    "Chartreuse (web),"      :  (127,255,0  ),
    "Cherry blossom pink"   :  (255,183,197),
    "Chestnut"              :  (205,92 ,92 ),
    "Chocolate"             :  (123,63 ,0  ),
    "Cinnabar"              :  (227,66 ,52 ),
    "Cinnamon"              :  (210,105,30 ),
    "Cobalt"                :  (0  ,71 ,171),
    "Columbia blue"         :  (155,221,255),
    "Copper"                :  (184,115,51 ),
    "Copper rose"           :  (153,102,102),
    "Coral"                 :  (255,127,80 ),
    "Coral pink"            :  (248,131,121),
    "Coral red"             :  (255,64 ,64 ),
    "Cordovan"              :  (137,63 ,69 ),
    "Corn"                  :  (251,236,93 ),
    "Cornflower blue"       :  (100,149,237),
    "Cosmic latte"          :  (255,248,231),
    "Cream"                 :  (255,253,208),
    "Crimson"               :  (220,20 ,60 ),
    "Cyan"                  :  (0  ,255,255),
    "Cyan"                  :  (0  ,183,235),
    "Dark blue"             :  (0  ,0  ,139),
    "Dark brown"            :  (101,67 ,33 ),
    "Dark cerulean"         :  (8  ,69 ,126),
    "Dark chestnut"         :  (152,105,96 ),
    "Dark coral"            :  (205,91 ,69 ),
    "Dark goldenrod"        :  (184,134,11 ),
    "Dark green"            :  (1  ,50 ,32 ),
    "Dark khaki"            :  (189,183,107),
    "Dark magenta"          :  (139,0  ,139),
    "Dark pastel green"     :  (3  ,192,60 ),
    "Dark pink"             :  (231,84 ,128),
    "Dark scarlet"          :  (86 ,3  ,25 ),
    "Dark salmon"           :  (233,150,122),
    "Dark slate gray"       :  (47 ,79 ,79 ),
    "Dark spring green"     :  (23 ,114,69 ),
    "Dark tan"              :  (145,129,81 ),
    "Dark turquoise"        :  (0  ,206,209),
    "Dark violet"           :  (148,0  ,211),
    "Davy's grey"           :  (85 ,85 ,85 ),
    "Deep carmine pink"     :  (239,48 ,56 ),
    "Deep cerise"           :  (218,50 ,135),
    "Deep chestnut"         :  (185,78 ,72 ),
    "Deep fuchsia"          :  (193,84 ,193),
    "Deep lilac"            :  (153,85 ,187),
    "Deep magenta"          :  (205,0  ,204),
    "Deep peach"            :  (255,203,164),
    "Deep pink"             :  (255,20 ,147),
    "Deep saffron"          :  (255,153,51 ),
    "Denim"                 :  (21 ,96 ,189),
    "Desert sand"           :  (237,201,175),
    "Dodger blue"           :  (30 ,144,255),
    "Duke blue"             :  (0  ,0  ,156),
    "Ecru"                  :  (194,178,128),
    "Egyptian blue"         :  (16 ,52 ,166),
    "Eggplant"              :  (97 ,64 ,81 ),
    "Electric blue"         :  (125,249,255),
    "Electric green"        :  (0  ,255,0  ),
    "Electric indigo"       :  (102,0  ,255),
    "Electric lime"         :  (204,255,0  ),
    "Electric Purple"       :  (191,0  ,255),
    "Emerald"               :  (80 ,200,120),
    "Fallow"                :  (193,154,107),
    "Falu red"              :  (128,24 ,24 ),
    "Feldgrau"              :  (77 ,93 ,83 ),
    "Fern green"            :  (79 ,121,66 ),
    "Firebrick"             :  (178,34 ,34 ),
    "Fire engine red"       :  (206,22 ,32 ),
    "Flax"                  :  (238,220,130),
    "Forest green"          :  (34 ,139,34 ),
    "French Rose"           :  (246,74 ,138),
    "Fuchsia"               :  (255,0  ,255),
    "Fuchsia Pink"          :  (255,119,255),
    "Gamboge"               :  (228,155,15 ),
    "Gold (metallic),"       :  (212,175,55 ),
    "Gold (web),"            :  (255,215,0  ),
    "Golden brown"          :  (153,101,21 ),
    "Golden poppy"          :  (252,194,0  ),
    "Golden yellow"         :  (255,223,0  ),
    "Goldenrod"             :  (218,165,32 ),
    "Grey"                  :  (128,128,128),
    "Gray-asparagus"        :  (70 ,89 ,69 ),
    "Green (color wheel),"   :  (0  ,255,0  ),
    "Green (HTML/CSS green" :  (0  ,128,0  ),
    "Green (pigment),"       :  (0  ,165,80 ),
    "Green (RYB),"           :  (102,176,50 ),
    "Green-yellow"          :  (173,255,47 ),
    "Han Blue"              :  (82 ,24 ,250),
    "Han Purple"            :  (82 ,24 ,250),
    "Harlequin"             :  (63 ,255,0  ),
    "Heliotrope"            :  (223,115,255),
    "Hollywood Cerise"      :  (244,0  ,161),
    "Hot Magenta"           :  (255,0  ,204),
    "Hot Pink"              :  (255,105,180),
    "Hunter green"          :  (53 ,94 ,59 ),
    "India green"           :  (19 ,136,8  ),
    "Indigo (dye),"          :  (0  ,65 ,106),
    "Indigo (web),"          :  (75 ,0  ,130),
    "International Klein Blue" : (0  ,47 ,167),
    "International orange"  :  (255,79 ,0  ),
    "Islamic green"         :  (0  ,144,0  ),
    "Ivory"                 :  (255,255,240),
    "Jade"                  :  (0  ,168,107),
    "Jungle green"          :  (41 ,171,135),
    "Kelly green"           :  (76 ,187,23 ),
    "Khaki"                 :  (195,176,145),
    "Light khaki"           :  (240,230,140),
    "Lava"                  :  (207,16 ,32 ),
    "Lavender (floral),"     :  (181,126,220),
    "Lavender (web),"        :  (230,230,250),
    "Lavender blue"         :  (204,204,255),
    "Lavender blush"        :  (255,240,245),
    "Lavender gray"         :  (196,195,208),
    "Lavender indigo"       :  (148,87 ,235),
    "Lavender magenta"      :  (238,130,238),
    "Lavender pink"         :  (251,174,210),
    "Lavender purple"       :  (150,123,182),
    "Lavender rose"         :  (251,160,227),
    "Lawn green"            :  (124,252,0  ),
    "Lemon"                 :  (253,233,16 ),
    "Lemon chiffon"         :  (255,250,205),
    "Light blue"            :  (173,216,230),
    "Light pink"            :  (255,182,193),
    "Light Thulian pink"    :  (230,143,172),
    "Lilac"                 :  (200,162,200),
    "Lime (color wheel),"    :  (191,255,0  ),
    "Lime (web),"            :  (0  ,255,0  ),
    "Lime green"            :  (50 ,205,50 ),
    "Linen"                 :  (250,240,230),
    "Liver"                 :  (83 ,75 ,79 ),
    "Magenta"               :  (255,0  ,255),
    "Magenta (dye),"         :  (202,21 ,123),
    "Magenta (process),"     :  (255,0  ,144),
    "Magic mint"            :  (170,240,209),
    "Magnolia"              :  (248,244,255),
    "Mahogany"              :  (192,64 ,0  ),
    "Maize"                 :  (251,236,94 ),
    "Majorelle Blue"        :  (96 ,80 ,220),
    "Malachite"             :  (11 ,218,81 ),
    "Maroon"                :  (128,0  ,0  ),
    "Maroon (X11),"          :  (176,48 ,96 ),
    "Mauve"                 :  (224,176,255),
    "Mauve Taupe"           :  (145,95 ,109),
    "Maya blue"             :  (115,194,251),
    "Medium blue"           :  (0  ,0  ,205),
    "Medium carmine"        :  (175,64 ,53 ),
    "Medium lavender magenta" : (204,153,204),
    "Medium purple"         :  (147,112,219),
    "Spring green"          :  (0  ,250,154),
    "Medium taupe"          :  (103,76 ,71 ),
    "Midnight blue"         :  (25 ,25 ,112),
    "Midnight green"        :  (0  ,73 ,83 ),
    "Mint green"            :  (152,255,152),
    "Misty rose"            :  (255,228,225),
    "Moss green"            :  (173,223,173),
    "Mountbatten pink"      :  (153,122,141),
    "Mustard"               :  (255,219,88 ),
    "Myrtle"                :  (33 ,66 ,30 ),
    "MSU Green"             :  (0  ,102,51 ),
    "Navajo white"          :  (255,222,173),
    "Navy Blue"             :  (0  ,0  ,128),
    "Ochre"                 :  (204,119,34 ),
    "Office green"          :  (0  ,128,0  ),
    "Old Gold"              :  (207,181,59 ),
    "Old Lace"              :  (253,245,230),
    "Old Lavender"          :  (121,104,120),
    "Old Rose"              :  (192,128,129),
    "Olive"                 :  (128,128,0  ),
    "Olive Drab"            :  (107,142,35 ),
    "Olivine"               :  (154,185,115),
    "Orange (color wheel),"  :  (255,127,0  ),
    "Orange (RYB),"          :  (251,153,2  ),
    "Orange (web),"          :  (255,165,0  ),
    "Orange Peel"           :  (255,160,0  ),
    "Orange-Red"            :  (255,69 ,0  ),
    "Orchid"                :  (218,112,214),
    "Pale blue"             :  (175,238,238),
    "Pale brown"            :  (152,118,84 ),
    "Pale carmine"          :  (175,64 ,53 ),
    "Pale chestnut"         :  (221,173,175),
    "Pale cornflower blue"  :  (171,205,239),
    "Pale magenta"          :  (249,132,229),
    "Pale pink"             :  (250,218,221),
    "Pale red-violet"       :  (219,112,147),
    "Pale taupe"            :  (188,152,126),
    "Papaya whip"           :  (255,239,213),
    "Pastel green"          :  (119,221,119),
    "Pastel pink"           :  (255,209,220),
    "Payne's grey"          :  (64 ,64 ,72 ),
    "Peach"                 :  (255,229,180),
    "Peach-orange"          :  (255,204,153),
    "Peach"                 :  (250,223,173),
    "Pear"                  :  (209,226,49 ),
    "Periwinkle"            :  (204,204,255),
    "Persian blue"          :  (28 , 57,187),
    "Persian green"         :  (0  ,166,147),
    "Persian indigo"        :  (50 ,18 ,122),
    "Persian orange"        :  (217,144,88 ),
    "Persian red"           :  (204,51 ,51 ),
    "Persian pink"          :  (247,127,190),
    "Persian rose"          :  (254,40 ,162),
    "Persimmon"             :  (236,88 ,0  ),
    "Pine Green"            :  (1  ,121,111),
    "Pink"                  :  (255,192,203),
    "Pink-orange"           :  (255,153,102),
    "Platinum"              :  (229,228,226),
    "Plum"                  :  (204,153,204),
    "Portland Orange"       :  (255,90 ,54 ),
    "Powder blue"           :  (176,224,230),
    "Puce"                  :  (204,136,153),
    "Prussian blue"         :  (0  ,49 ,83 ),
    "Psychedelic purple"    :  (221,0  ,255),
    "Pumpkin"               :  (255,117,24 ),
    "Purple"                :  (127,0  ,127),
    "Purple (X11),"          :  (160,92 ,240),
    "Purple Taupe"          :  (80 ,64 ,77 ),
    "Raspberry"             :  (227 ,11,92 ),
    "Raw umber"             :  (115,74 ,18 ),
    "Razzmatazz"            :  (227,37 ,107),
    "Red"                   :  (255,0  ,0  ),
    "Red (pigment),"         :  (237,28 ,36 ),
    "Red"                   :  (254,39 ,18 ),
    "Red-violet"            :  (199,21 ,133),
    "Rich carmine"          :  (215,0  ,64 ),
    "Robin egg blue"        :  (0  ,204,204),
    "Rose"                  :  (255,0  ,127),
    "Rose Madder"           :  (227,38 ,54 ),
    "Rose pink"             :  (255,102,204),
    "Rose quartz"           :  (170,152,169),
    "Rose Taupe"            :  (144,93 ,93 ),
    "Royal blue"            :  (65 ,105,225),
    "Royal purple"          :  (107,63 ,160),
    "Ruby"                  :  (224,17 ,95 ),
    "Russet"                :  (128,70 ,27 ),
    "Rust"                  :  (183,65 ,14 ),
    "Safety orange"         :  (255,102,0  ),
    "Saffron"               :  (244,196,48 ),
    "Salmon"                :  (255,140,105),
    "Salmon pink"           :  (255,145,164),
    "Sandy brown"           :  (244,164,96 ),
    "Sangria"               :  (146,0  ,10 ),
    "Sapphire"              :  (8  ,37 ,103),
    "Scarlet"               :  (255,36 ,0  ),
    "School bus yellow"     :  (255,216,0  ),
    "Sea Green"             :  (46 ,139,87 ),
    "Seal brown"            :  (50 ,20 ,20 ),
    "Seashell"              :  (255,245,238),
    "Selective yellow"      :  (255,186,0  ),
    "Sepia"                 :  (112,66 ,20 ),
    "Shamrock green"        :  (0  ,158,96 ),
    "Shocking Pink"         :  (252,15 ,192),
    "Sienna"                :  (160,82 ,46 ),
    "Silver"                :  (192,192,192),
    "Sky Blue"              :  (135,206,235),
    "Slate gray"            :  (112,128,144),
    "Smalt"                 :  (0  ,51 ,153),
    "Spring bud"            :  (167,252,0  ),
    "Spring green"          :  (0  ,255,127),
    "Steel blue"            :  (70 ,130,180),
    "Tan"                   :  (210,180,140),
    "Tangerine"             :  (242,133,0  ),
    "Tangerine yellow"      :  (255,204,0  ),
    "Taupe"                 :  (72 ,60 ,50 ),
    "Taupe gray"            :  (139,133,137),
    "Tea Green"             :  (208,240,192),
    "Tea Rose (orange),"     :  (248,131,194),
    "Tea rose (rose),"       :  (244,194,194),
    "Teal"                  :  (0  ,128,128),
    "Tenne"                 :  (205,87 ,0  ),
    "Terra cotta"           :  (226,114,91 ),
    "Thistle"               :  (216,191,216),
    "Thulian pink"          :  (222,111,161),
    "Tomato"                :  (255,99 ,71 ),
    "Turquoise"             :  (48 ,213,200),
    "Tyrian purple"         :  (102,2  ,60 ),
    "Ultramarine"           :  (18 ,10 ,143),
    "Ultra pink"            :  (255,111,255),
    "United Nations blue"   :  (91 ,146,229),
    "Upsdell red"           :  (174,22 ,32 ),
    "Vegas Gold"            :  (197,179,88 ),
    "Venetian red"          :  (200,8  ,21 ),
    "Vermilion"             :  (227,66 ,51 ),
    "Violet"                :  (139,0  ,255),
    "Violet (web),"          :  (238,130,238),
    "Violet (RYB),"          :  (2  ,71 ,54 ),
    "Viridian"              :  (64 ,130,109),
    "Wheat"                 :  (245,222,179),
    "White"                 :  (255,255,255),
    "Wisteria"              :  (201,160,220),
    "Xanadu"                :  (115,134,120),
    "Yale Blue"             :  (15 ,77 ,146),
    "Yellow"                :  (255,255,0  ),
    "Yellow (process),"      :  (255,239,0  ),
    "Yellow (RYB),"          :  (254,254,51 ),
    "Yellow-green"          :  (154,205,50 ),
}


colour_names = list(rgb_data.iterkeys())
colour_names.sort(key = len, reverse=True)

default_spread = 0.04
common_spread_default = 0.1
colour_spreads = collections.defaultdict(
    lambda : float(default_spread),
    ( (cname, common_spread_default) for cname in (
        "Red", "Green", "Blue",
        "Yellow", "Black", "White"
        )))
